<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<style>
    .laytp-container .layui-tree-other .layui-tree-txt {color: #555 !important;}
</style>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">任务名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">任务编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <label class="layui-form-label">执行人</label>
                        <div class="layui-input-block">
                            <input type="text" name="zhiname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="enginname" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">任务类别：</label>
                        <div class="layui-input-block">
                            <select id="type" name="type" lay-filter="type">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">优先级：</label>
                        <div class="layui-input-block">
                            <select id="youxian" name="youxian" lay-filter="youxian">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">计划开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="planstartdt" placeholder="请选择" autocomplete="off" class="layui-input bdate_sea_range_ymdhi">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">计划结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="planenddt" placeholder="请选择" autocomplete="off" class="layui-input bdate_sea_range_ymdhi">
                        </div>
                    </div>
                    <div class="layui-col-md3 search_hide none">
                        <label class="layui-form-label">实际完成时间</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="enddt" placeholder="请选择" autocomplete="off" class="layui-input bdate_sea_range_ymdhi">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <input type="hidden" id="status" name="status" value="0">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
                                <div id="search_open" onclick="toggle_search()">
                                    <i class="layui-icon layui-icon-down"></i>展开
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md2" id="navselect">
                <div class="navselect_bac">
                    <div class="navselect_div">
                        <div class="navselect_title">任务状态</div>
                    </div>
                    <div id="tree_content"></div>
                </div>
            </div>

            <div class="layui-col-md10" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.id}}')">查看</a>
        {{# if(d.status != 7){ }}
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_edit('{{d.id}}')">编辑</a>
        {{#} }}
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_delete('{{d.id}}')">删除</a>
        {{# if(d.status != 7){ }}
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_close('{{d.id}}')">关闭</a>
        {{#} }}
    </div>
</script>

<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
        <button class="layui-btn layui-btn-primary outbut" onclick="auth_but_func_add('新建')">
            <i class="layui-icon layui-icon-add-1"></i>新建
        </button>
    </div>
</script>

<script>
    var mytable, table, form, treeObj, deptTreeData=[];

    var deptTreeData = [
        {id:0, title:'全部'},
        {id:1, title:'待执行'},
        {id:3, title:'进行中'},
        {id:5, title:'已完成'},
        {id:7, title:'已关闭'},
    ];

    getDeptData();
    function getDeptData(){
        layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable'], function () {
            var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;
            treeObj = tree.render({
                elem: '#tree_content'
                ,id: 'tree_content'
                ,data: deptTreeData
                ,onlyIconControl: true
                ,click: function(obj){
                    $("#status").val(obj.data.id)
                    searchTableFunc(form, table);

                    $('.layui-tree-entry').each(function () {
                        $(this).find('.layui-tree-txt').removeClass('layui-tree-other');
                    });
                    $(obj.elem).find('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');
                }
            });
            var height = $('.laytp-container').height() - 220 + 'px';
            $('#tree_content').css('cssText','max-height:'+height);

            var curType = $("#status").val();
            $("#tree_content").find('div[data-id="'+curType+'"]').find('.layui-tree-entry').eq(0).find('.layui-tree-txt').addClass('layui-tree-other');
        });
    }
    layui.use(["laytp",'tree','laypage','table','dropdown','form','soulTable', 'element'], function () {
        var tree = layui.tree,laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;
        var element = layui.element;
        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });

        setSouTableExport('我分配的任务');
        mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_task_list),where: {status:0}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text
            ,parseData: function (res) {
                deptTreeData = res.data.nav
                getDeptData();


                var youxian_str = '<option value="">请选择</option>';
                var youxian = res.data.youxian;
                for (var key in youxian){
                    if(res.data.is_youxian == key){
                        youxian_str += '<option value="'+youxian[key]+'" selected>'+youxian[key]+'</option>';
                    }else {
                        youxian_str += '<option value="'+youxian[key]+'">'+youxian[key]+'</option>';
                    }

                }
                $("#youxian").html(youxian_str);

                var type_str = '<option value="">请选择</option>';
                var type = res.data.type;
                for (var key in type){
                    if(res.data.is_type == key){
                        type_str += '<option value="'+key+'" selected>'+type[key]+'</option>';
                    }else {
                        type_str += '<option value="'+key+'">'+type[key]+'</option>';
                    }

                }
                $("#type").html(type_str);

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type: "checkbox", fixed: 'left'}
                ,{type:'numbers',title:'序号',fixed:'left'}
                ,{field: 'name', title: '任务名称',width:240}
                ,{field: 'number', title: '任务编号'}
                ,{field: 'status_name', title: '任务状态'}
                ,{field:'rate',title:'完成比例(%)',templet: function(d){
                        var str = '<div class="layui-progress layui-progress-big" lay-showPercent="yes" style="margin-top:10px">';
                        str += '<div class="layui-progress-bar" lay-percent="'+d.rate+'%"></div></div>';
                        return str;
                    }}
                ,{field: 'type_name', title: '任务类别'}
                ,{field: 'youxian', title: '优先级'}
                ,{field: 'zhier_name', title: '执行人'}
                ,{field: 'planstartdt', title: '计划开始时间'}
                ,{field: 'planenddt', title: '计划结束时间'}
                ,{field: 'enddt', title: '实际完成时间'}
                ,{field: 'explain', title: '任务描述'}
                ,{field: 'enginname', title: '项目名称'}
                ,{field: 'created_user_name', title: '分配人'}
                ,{field: 'created_at', title: '分配时间'}
                ,{fixed: 'right', title:'操作', toolbar: '#test-dropdown-toolbar-barDemo',align:'center',width:200}
            ]]
            , done: function (res) {
                element.render();
                soulTable.render(this);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_show(buttitle, id){
        openPage('show.php?id='+id);
    }
    function auth_but_func_add(){
        openPageEdit('add.php?close=1');
    }
    function auth_but_func_edit(id){
        openPageEdit('edit.php?close=1&id='+id);
    }
    function auth_but_func_close(id){
        openPageEdit('close.php?id='+id, '770px', '490px');
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_task_del, {id:trData.id});
    }


</script>
</body>
</html>
